###***Updates Mars's Mass to include mass passed inward from the disk, recalculates the radius of Mars, then checks to see if the radius***###
###***of Mars has grown pass the interior of the disk.  If so, repositions the interior of the disk and adds the mass in those bins***###
###***to Mars_Accrete.    'x' is the timestep, y is Mars_Accrete, z is location of interior bin***###  Mars_Accrete needs to be set to zero after

from __future__ import division
from math import *
from Init_Cond import *

def f(x,y,z, R_Embryo):     #checks if Embryo has grown large enough to swallow up inner disk
#x is mass of the embryo
    M = x
    Mars_Accrete = y
    inside = z
    addmass = 0.0


    while (3.0*(M + Mars_Accrete + addmass)/(4.0*pi*rho))**(1/3) > r[inside]:
        inside = int(round(((3.0*(M + Mars_Accrete + addmass)/(4.0*pi*rho))**(1/3) - r_I)/deltar - .5)) + 1 #identify bin embryo extends to, +1 to get neighboring
            #need to + 1, otherwise embryo could extend to 99% of identified bin.  Disk needs to exist OUTSIDE embryo surface
        addmass = sum(m[0:inside-1])


    Mars_Accrete = Mars_Accrete + addmass

    return Mars_Accrete, inside

# def g(x,y,z,q,deltat):   #x is timestep, q is a switch
def g(inside):  #Zeroes out swallowed up bins
    # Mars_Accrete = y
    # inside = z
    # y = sum(sigma)

    # for a in range(inside):
    for a in range(inside - 1):
        m[a] = 0.0
        sigma[a] = 0.0